/*
 * Copyright (c) 2005, 2014 vacoor
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 */
package org.vacoor.nothing.misc.rmc.session;


import org.vacoor.nothing.misc.rmc.binding.MapperProxyFactory;

import java.util.HashMap;
import java.util.Map;

/**
 * @author vacoor
 */
public class Session {
    private Map<Class<?>, MapperProxyFactory<?>> proxyFactoryCache = new HashMap<Class<?>, MapperProxyFactory<?>>();

    public <T> T getMapper(Class<T> mapperInterface) {
        MapperProxyFactory<T> mapperProxyFactory = (MapperProxyFactory<T>) proxyFactoryCache.get(mapperInterface);
        if (mapperProxyFactory == null) {
            mapperProxyFactory = new MapperProxyFactory(mapperInterface);
            proxyFactoryCache.put(mapperInterface, mapperProxyFactory);
        }
        return mapperProxyFactory.newProxy(this);
    }
}
